

package com.mt.repair.controller.repairManagement;

import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mt.repair.dto.repairManagement.DeviceCatUserEditDto;
import com.mt.repair.entity.repairManagement.DeviceCatUser;
import com.mt.repair.service.repairManagement.DeviceCatUserService;
				import com.mt.repair.service.repairManagement.DeviceService;
				import com.mt.common.system.service.UserService;
						

@Api(tags = "设备用户关联表")
@RestController
@RequestMapping("/api/repair/repairManagement/DeviceCatUser")
@CrossOrigin(allowCredentials = "true")
public class DeviceCatUserController {
private static Logger logger = LoggerFactory.getLogger(DeviceCatUserController.class);



															
														
																				@Autowired private DeviceCatUserService deviceCatUserService;
		@Autowired private DeviceService deviceService;
		@Autowired private UserService userService;
	
	/**
	* 根据分页参数查询设备用户关联表集合
	*
	* @param pageDTO 分页条件
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:view')")
	@ApiOperation("分页查询设备用户关联表")
	@ApiPageParam
	@PostMapping("/findDeviceCatUsers")
	public PageResultDTO findDeviceCatUsers(@RequestBody PageDTO pageDTO){
		return this.deviceCatUserService.findDeviceCatUsers(pageDTO);
	}

	/**
	* 根据ID查询指定的设备用户关联表
	*
	* @param deviceCatUserId Id
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:view')")
	@ApiOperation("根据id查询设备用户关联表")
	@ApiPageParam
	@PostMapping("/findDeviceCatUser")
	public DeviceCatUser findDeviceCatUser(@RequestParam Long deviceCatUserId){
		return this.deviceCatUserService.findDeviceCatUser(deviceCatUserId);
	}

	/**
	* 根据ID查询指定的设备用户关联表(包含外键名称)
	*
	* @param deviceCatUserId Id
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:view')")
	@ApiOperation("根据ID查询指定的设备用户关联表(包含外键名称)")
	@PostMapping("/findDeviceCatUserForView")
	public DeviceCatUser findDeviceCatUserForView(@RequestParam Long deviceCatUserId){
		return this.deviceCatUserService.findDeviceCatUserWithForeignName(deviceCatUserId);
	}

	/**
	* 根据ID查询指定的设备用户关联表(包含设备用户关联表和外键名称)
	*
	* @param deviceCatUserId Id
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:view')")
	@ApiOperation("根据ID查询指定的设备用户关联表(包含设备用户关联表和外键名称)")
	@PostMapping("/findDeviceCatUserForEdit")
	public DeviceCatUserEditDto findDeviceCatUserForEdit(@RequestParam Long deviceCatUserId){
				DeviceCatUserEditDto deviceCatUserEditDto = new DeviceCatUserEditDto();
		deviceCatUserEditDto.setDeviceCatUser(this.deviceCatUserService.findDeviceCatUserWithForeignName(deviceCatUserId));

		this.prepareDeviceCatUserEditDto(deviceCatUserEditDto);

		return deviceCatUserEditDto;
	}

	/**
	* 根据ID查询指定的设备用户关联表(只提取ID 和 Name)
	*
	* @param deviceCatUserId Id
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:view')")
	@ApiOperation("根据ID查询指定的设备用户关联表(只提取ID 和 Name)")
	@PostMapping("/findDeviceCatUsersWithIdNameById")
	public DeviceCatUser findDeviceCatUsersWithIdNameById(@RequestParam Long deviceCatUserId){
	return this.deviceCatUserService.findDeviceCatUsersWithIdNameById(deviceCatUserId);
	}

	/**
	* 根据名称查询设备用户关联表集合(只提取ID 和 Name)
	*
	* @param deviceCatUserName 名称
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:view')")
	@ApiOperation("根据名称查询设备用户关联表集合(只提取ID 和 Name)")
	@PostMapping("/findDeviceCatUsersWithIdNameByName")
	public List<DeviceCatUser> findDeviceCatUsersWithIdNameByName(@RequestParam String deviceCatUserName){
	return this.deviceCatUserService.findDeviceCatUsersWithIdNameByName(deviceCatUserName);
	}


	/**
	* 创建新的设备用户关联表
	*
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:add')")
	@ApiOperation("创建新的设备用户关联表")
	@PostMapping("/createDeviceCatUser")
	public DeviceCatUserEditDto createDeviceCatUser(){
				DeviceCatUserEditDto deviceCatUserEditDto = new DeviceCatUserEditDto();
		deviceCatUserEditDto.setDeviceCatUser(new DeviceCatUser());

		this.prepareDeviceCatUserEditDto(deviceCatUserEditDto);
		return deviceCatUserEditDto;
	}

	private void prepareDeviceCatUserEditDto(DeviceCatUserEditDto deviceCatUserEditDto){
												        //TODO: 以下代码可以注释掉，此行代码即时加载所有外键对象，以便选择。如果不在此加载，可以在界面上实现延迟加载。如果外键对象超过 500 行，建议采用延迟加载
		deviceCatUserEditDto.setDeviceDevices(this.deviceService.findAllDevicesWithIdName());
											        //TODO: 以下代码可以注释掉，此行代码即时加载所有外键对象，以便选择。如果不在此加载，可以在界面上实现延迟加载。如果外键对象超过 500 行，建议采用延迟加载
		deviceCatUserEditDto.setUserUsers(this.userService.findAllUsersWithIdName());
																			}

	/**
	* 新增保存设备用户关联表
	*
	* @param deviceCatUser 实体对象
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:add')")
	@ApiOperation("新增保存设备用户关联表")
	@PostMapping("/saveDeviceCatUser")
	public DeviceCatUser saveDeviceCatUser(@RequestBody DeviceCatUser deviceCatUser){
		return this.deviceCatUserService.saveDeviceCatUser(deviceCatUser);
	}

	/**
	* 修改保存设备用户关联表
	*
	* @param deviceCatUser 实体对象
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:update')")
	@ApiOperation("修改保存设备用户关联表")
	@PostMapping("/updateDeviceCatUser")
	public DeviceCatUser updateDeviceCatUser(@RequestBody DeviceCatUser deviceCatUser){
		return this.deviceCatUserService.updateDeviceCatUser(deviceCatUser);
	}

	/**
	* 根据ID删除设备用户关联表
	*
	* @param deviceCatUserId ID
	*/
	@PreAuthorize("hasAuthority('repair:repairManagement:DeviceCatUser:remove')")
	@ApiOperation("根据ID删除设备用户关联表")
	@PostMapping("/deleteDeviceCatUser")
	public void deleteDeviceCatUser(@RequestParam Long deviceCatUserId){
		this.deviceCatUserService.deleteDeviceCatUser(deviceCatUserId);
	}



}

